package com.zmn.brs.model.query.rule;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zmn.brs.model.vo.rule.objective.ObjectiveRuleVO;
import lombok.Data;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 描述：
 *
 * @author chongw
 * @since 2021-06-01 11:04
 */
@Data
public class ObjectiveRuleCustom {

    private Integer ruleId;

    private Integer eventId;

    private Integer eventCode;

    private Integer status;

    private Integer thresholdId;

    private String thresholdValue;

    private Integer cubeSnapshotId;

    private Integer cubeMeasureId;

    private Integer droolsId;

    private String droolsName;

    private String computeTime;

    private String pushTime;

    private String monitorCycle;

    private Integer ruleRealStatus;

    private ObjectiveRuleVO data;

    private EarlyWarningConfig rule1;

    private EarlyWarningConfig rule2;

    private EarlyWarningConfig rule3;

    public EarlyWarningConfig getRule1(){
        return this.getRule(1);
    }

    public EarlyWarningConfig getRule2(){
        return this.getRule(2);
    }

    public EarlyWarningConfig getRule3(){
        return this.getRule(3);
    }

    private EarlyWarningConfig getRule(Integer level){
        List<EarlyWarningConfig> temp = getData().getList().stream().filter(o ->{
            return o.getKey() == level;
        }).collect(Collectors.toList());
        return Optional.ofNullable(temp.get(0)).orElse(new EarlyWarningConfig());
    }

    public ObjectiveRuleVO getData(){
        if(this.thresholdValue == null){
            return ObjectiveRuleVO.builder().build();
        }
        return JSONObject.parseObject(this.thresholdValue , ObjectiveRuleVO.class);
    }

}
